package edu.mit.media.fv.layers
{
	import edu.mit.media.fv.blocks.*;
	import edu.mit.media.fv.components.*;
	import edu.mit.media.fv.events.*;
	import edu.mit.media.fv.fluidspace.*;
	import edu.mit.media.fv.icons.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.text.*;
	public class ActiveLayer extends Layer
	{
		public function ActiveLayer(x:int = 0, y:int = 0, width:int = 650, height:int = 100)
		{
			super(x, y, width, height, null);
			this._wall = new Sprite();
			this.addChild(this._wall);
			this._label = new TextField();
			this._canvas = new Sprite();
			this.addChild(this._canvas);
			this.reform();
			this.filters = [];
		}
		public override function reform():void{
			this._viewbounds = new Rectangle(0, 0,this.layerWidth, this.layerHeight);
			this._wall.graphics.clear();
			this._wall.graphics.beginFill(0xFF0000, 0.0);
			this._wall.graphics.drawRect(0,0,this.layerWidth, this.layerHeight);
			this._wall.graphics.endFill();
		}
		public override function addBlock(block:Block):void{
			super.addBlock(block);
			if(block == null){ return;}
			this._canvas.addChild(block);
			block.diameter = this.layerHeight;
			block.y = 0;
		}
		public override function dropBlock(block:Block):void{
			trace("dropping block onto the active layer");
			if(block.blockContainer == this){
				block.moveBlock(this);
			}else{
				var pp:Point = this.globalToLocal(block.localToGlobal(new Point(0, 0)));
				
				block.snapBack();
				var newBlock:Block = block.model.getActiveInstance();
				if(newBlock != null){
					newBlock.x = pp.x;
					newBlock.y = pp.y;
					this.addBlock(newBlock);
				}
			}
		}
	}
}